<?php
	include_once 'SimpleObjectDAO.php';
	include_once 'InterfaceDAO.php';
	include_once "BMetier/Art.class.php";
	
	/**
	 * DAO of class Art 
	 */
	class ArtDAO extends SimpleObjectDAO implements InterfaceDAO {

		public static function store(Art $art) {
			if($art != null) {
				if($art->getId() == null) {
					$req = "Insert into art set art ='". $art->getArt()."'";
					@mysql_query($req) or die('ERROR : Insert art '.$req);
					$art->setId(intval(mysql_insert_id()));
				}else {
					$req = "Update art set art = '". $art->getArt() ."' where id = " . $art->getId();
					@mysql_query($req) or die('ERROR : Update art ' .$req);
				}
				return $art;
			}
		}

		public static function delete(Art $art){
			if($art != null) {
				if($art->getId() != null) {
					$req = "Delete From art where id = " . $art->getId();
					@mysql_query($req) or die('ERROR : delete art'.$req);
				}
			}
		}

		public static function load($id) {
			if($id != null) {
				$req = "Select id, art From art where id = " . $id;
				$res = @mysql_query($req) or die('ERROR : select art'.$req);
				if (mysql_num_rows($res) == 0) {
					return ;
				}
				echo'aaa';
				$art = new Art();
 				while($row = mysql_fetch_assoc($res)){
 					echo $row['art'];
   					$art->setId(intval($row['id']));
   					$art->setArt($row['art']);
				}
				echo'eee';
				return $art;
			}
		}
	}

?>